package ocean.chinacraft.common.world.gen.features;

import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.WorldGenRegistries;
import net.minecraft.world.gen.blockplacer.SimpleBlockPlacer;
import net.minecraft.world.gen.blockstateprovider.SimpleBlockStateProvider;
import net.minecraft.world.gen.feature.*;
import net.minecraft.world.gen.foliageplacer.BlobFoliagePlacer;
import net.minecraft.world.gen.trunkplacer.StraightTrunkPlacer;
import ocean.chinacraft.common.ModBlocks;

/**
 * 物品配置
 *
 * @author zhang
 * @since 2021/11/30
 */
public class ModConfiguredFeatures {

    /**
     * 桑树
     */
    public static final ConfiguredFeature<BaseTreeFeatureConfig, ?> MULBERRY_TREE =
            register("mulberry_tree", Feature.TREE.configured((
                    new BaseTreeFeatureConfig.Builder(
                            new SimpleBlockStateProvider(ModBlocks.MULBERRY_LOG.get().defaultBlockState()),
                            new SimpleBlockStateProvider(ModBlocks.MULBERRY_LEAVES.get().defaultBlockState()),
                            new BlobFoliagePlacer(FeatureSpread.fixed(2), FeatureSpread.fixed(0), 3),
                            new StraightTrunkPlacer(6, 4, 3),
                            new TwoLayerFeature(1, 0, 1))).ignoreVines().build()));

    /**
     * 映山红
     */
    public static final ConfiguredFeature<?, ?> AZALEA_FLOWER = Feature.FLOWER.configured((
                    new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(ModBlocks.AZALEA.get().defaultBlockState()),
                            SimpleBlockPlacer.INSTANCE)).tries(1).build())
            .decorated(Features.Placements.HEIGHTMAP_SQUARE).count(1);

    /**
     * 牡丹
     */
    public static final ConfiguredFeature<?, ?> PEONY_FLOWER = Feature.FLOWER.configured((
                    new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(ModBlocks.PEONY.get().defaultBlockState()),
                            SimpleBlockPlacer.INSTANCE)).tries(1).build())
            .decorated(Features.Placements.HEIGHTMAP_SQUARE).count(1);

    /**
     * 菊花
     */
    public static final ConfiguredFeature<?, ?> CHRYSANTHEMUM_FLOWER = Feature.FLOWER.configured((
                    new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(ModBlocks.CHRYSANTHEMUM.get().defaultBlockState()),
                            SimpleBlockPlacer.INSTANCE)).tries(1).build())
            .decorated(Features.Placements.HEIGHTMAP_SQUARE).count(1);

    /**
     * 雷笋
     */
    public static final ConfiguredFeature<?, ?> LIGHTNING_BAMBOO_SAPLING = Feature.FLOWER.configured((
                    new BlockClusterFeatureConfig.Builder(new SimpleBlockStateProvider(ModBlocks.LIGHTNING_BAMBOO_SAPLING.get().defaultBlockState()),
                            SimpleBlockPlacer.INSTANCE)).tries(5).build())
            .decorated(Features.Placements.HEIGHTMAP_SQUARE).count(1);

    private static <FC extends IFeatureConfig> ConfiguredFeature<FC, ?> register(String key,
                                                                                 ConfiguredFeature<FC, ?> configuredFeature) {
        return Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, key, configuredFeature);
    }
}
